package com.sanpu.kxe.common.view;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.module.roundview.RoundTextView;

import butterknife.ButterKnife;

/**
 * Description：自定义item
 * Created by 薛勇军 on 2018/7/10.
 */

public class UserCenterItem extends LinearLayout {
    protected TextView vTitle;
    protected TextView vDes;
    protected ImageView vIcon;
    protected RoundTextView vBadge;
    protected ImageView vArrow;

    protected String title;
    protected String des;
    protected int icon;
    protected boolean hasArraw;

    public UserCenterItem title(String title) {
        this.title = title;
        return this;
    }

    public UserCenterItem icon(int icon) {
        this.icon = icon;
        return this;
    }

    public UserCenterItem des(String des) {
        this.des = des;
        vDes.setText(des);
        return this;
    }

    public UserCenterItem(Context context, int id, String title, String des, int icon, boolean hasArraw) {
        super(context);
        setId(id);
        this.title = title;
        this.icon = icon;
        this.des = des;
        this.hasArraw = hasArraw;

        LayoutInflater.from(getContext()).inflate(R.layout.item_user_center, this);
        vIcon = ButterKnife.findById(this, R.id.icon);
        vTitle = ButterKnife.findById(this, R.id.title);
        vDes = ButterKnife.findById(this, R.id.des);
        vBadge = ButterKnife.findById(this, R.id.badge);
        vArrow = ButterKnife.findById(this, R.id.arrow);
        show();
    }

    public UserCenterItem(Context context, int id, String title, String des) {
        this(context, id, title, des, 0, true);
    }

    public UserCenterItem(Context context, int id, String title, int icon) {
        this(context, id, title, "", icon, true);
    }


    public UserCenterItem(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
    }

    public UserCenterItem show() {
        if(!TextUtils.isEmpty(title))
            vTitle.setText(title);
        if(!TextUtils.isEmpty(des))
            vDes.setText(des);
        vTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.c_4a4a4a));
        if (icon == 0) {
            vIcon.setVisibility(GONE);
        } else {
            vIcon.setVisibility(VISIBLE);
            vIcon.setBackgroundResource(icon);
        }
        vArrow.setVisibility(hasArraw ? VISIBLE : INVISIBLE);
        return this;
    }
}
